package logic

import (
	"context"
	"wechat/models/mysql"

	"wechat/wechatrpc/internal/svc"
	"wechat/wechatrpc/wechatrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type WeListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewWeListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *WeListLogic {
	return &WeListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 列表展示
func (l *WeListLogic) WeList(in *wechatrpc.WeListRequest) (*wechatrpc.WeListResponse, error) {
	// todo: add your logic here and delete this line

	var wechar []mysql.WeChat

	mysql.DB.Debug().Where("id = ?", in.Id).Find(&wechar)

	var weList []*wechatrpc.WeList

	for _, i2 := range wechar {
		list := wechatrpc.WeList{
			Image:        i2.Image,
			NickName:     i2.NickName,
			WeiXinNumber: i2.WeiXinNumber,
			Address:      i2.Address,
		}
		weList = append(weList, &list)
	}

	return &wechatrpc.WeListResponse{
		List: weList,
	}, nil
}
